package com.example.xd.socketmodule;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @auther XuDan on 2020/5/7.
 */
public class TestServer {

    public static void main(String[] args) throws IOException {
        startSocket();
    }

    private static void startSocket() throws IOException {
        byte[] buf = new byte[1024];
        DatagramSocket ds = new DatagramSocket(5432);

        //接收从客户端发送过来的数据
        DatagramPacket dp_receive = new DatagramPacket(buf, 1024);
        System.out.println("xd-----------server is on，waiting for client to send data......");
        boolean f = true;
        while (f) {
            //服务器端接收来自客户端的数据
            System.out.println("server received data from client：");
            ds.receive(dp_receive);
            String str_receive = " from " + dp_receive.getAddress().getHostAddress() + ":" + dp_receive.getPort();
            System.out.println("xd-----------" + str_receive);
        }
        ds.close();

    }
}
